package com.cow.support.remote;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.remoting.caucho.HessianServiceExporter;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.util.NestedServletException;

public class OurServiceExporter extends HessianServiceExporter implements HttpRequestHandler {   
  
    @Override  
    public void handleRequest(HttpServletRequest request,    
                              HttpServletResponse response)    
                              throws ServletException, IOException {   
        if (!"POST".equals(request.getMethod())) {   
            throw new HttpRequestMethodNotSupportedException(   
                      request.getMethod(),   
                      new String[]{"POST"},    
                     "HessianServiceExporter only supports POST requests");   
        }   
        response.setContentType("HESSIAN"); //CONTENT_TYPE_HESSIAN  
        try {   
            HessianContext.setRequest(request); 
            invoke(request.getInputStream(), response.getOutputStream());   
        }   
        catch (Throwable ex) {   
            logger.error("Hessian skeleton invocation failed");   
            throw new NestedServletException("Hessian skeleton invocation failed", ex);   
        }   
        finally {   
            HessianContext.clear();   
        }   
    }   
    
}  
